<!DOCTYPE HTML>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<meta charset="utf-8">
<head>
    <th:block th:include="include :: header('入库作业管理')"/>
    <th:block th:include="include :: layout-latest-css"/>
    <th:block th:include="include :: ztree-css"/>
    <style>

    </style>
</head>
<body class="gray-bg">
<div class="container-div">
    <div class="col-sm-12 search-collapse">
        <form id="user-form">
            <div class="select-list">
                <ul>
                    <input type="text" name="inOut" value="1" hidden/>
                    <li>
                        <label>作业状态：</label>
                        <select id="status" name="status" th:height="300px">
<!--                            <option value="">-&#45;&#45;请选择-&#45;&#45;</option>-->
                            <option value="0" selected="selected">待执行</option>
                            <option value="1" >未执行</option>
<!--                        <option value="2">待执行</option>-->
                            <option value="3" >正执行</option>
                            <option value="4">已完成</option>
                            <option value="5">已作废</option>

                        </select>
                    </li>
                    <li>
                        <label>任务号：</label><input type="text" name="taskNo"/>
                    </li>
                    <li>
                        <label>托盘条码：</label><input type="text" name="trayCode"/>
                    </li>
                    <li>
                        <label>巷道：</label><input type="text" name="roadwayId"/>
                    </li>
                    <li>
                        <label>建立时间：</label><input type="text" placeholder="请单击选择开始时间：" name="startTime" id="startTime"/>---
                        <input type="text" placeholder="请单击选择结束时间：" name="finishTime" id="finishTime"/>
                    </li>
                    <li>
                        <label>物资编号：</label><input type="text" name="productId"/>
                    </li>
                    <li>
                        <label>入库单号：</label><input type="text" name="inOrOutId"/>
                    </li>
                    <li>
                        <label>子件条码：</label><input type="text" name="barcodeDetail"/>
                    </li>

                    <li>
                        入库类型：
                        <select id="inOrOut" name="inOrOut" th:height="300px">
                            <!--<option value="">&#45;&#45;请选择&#45;&#45;</option>-->
                            <!--<option value="1">物资入库</option>-->
                            <!--<option value="2">托盘入库</option>-->
                            <!--<option value="3">回流入库</option>-->
                            <!--<option value="4">盘点入库</option>-->
                        </select>
                    </li>
                    <li>
                        <label>入库层：</label>
                        <select id="workshopId" name="workshopId">
                            <option value="" selected="selected">请选择</option>
                            <option value="2" >2层</option>
                            <option value="3" >3层</option>
                        </select>
                    </li>

                    <li>
                        <label>入库口：</label>
                        <select name="entranceId" th:with="type=${@dict.getType('entrance_id')}">
                            <option value="">所有</option>
                            <option th:each="dict : ${type}" th:text="${dict.dictLabel}"
                                    th:value="${dict.dictValue}"></option>
                        </select>
                    </li>

                    <li>
                        <a class="btn btn-primary btn-rounded btn-sm" onclick="$.table.search()"><i
                                class="fa fa-search"></i>&nbsp;搜索</a>
                        <a class="btn btn-warning btn-rounded btn-sm" onclick="$.form.reset()"><i
                                class="fa fa-refresh"></i>&nbsp;重置</a>
                    </li>
                </ul>
            </div>
        </form>
    </div>
    <div class="btn-group-sm" id="toolbar" role="group">
        <a class="btn btn-success" onclick="changeJobStatus()" shiro:hasPermission="mydo:mydojob:changeJobStatus">
            <i class="fa fa-caret-down"></i> 更改作业状态
        </a>
        <a class="btn btn-success" onclick="changeJobpriority(1)" shiro:hasPermission="mydo:mydojob:changeJobStatus">
            <i class="fa fa-caret-down"></i> 提高优先级
        </a>
        <a class="btn btn-success" onclick="changeJobpriority(2)" shiro:hasPermission="mydo:mydojob:changeJobStatus">
            <i class="fa fa-caret-down"></i> 降低优先级
        </a>
        <a class="btn btn-success" onclick="handFinish()" shiro:hasPermission="mydo:mydojob:handFinish">
            <i class="fa fa-plus"></i> 手动完成
        </a>
        <a class="btn btn-danger" style="background-color: red" onclick="handInvalid()"
           shiro:hasPermission="mydo:mydojob:handInvalid">
            <i class="fa fa-trash-o"></i> 手动作废
        </a>
    </div>

    <div id="div1" style="height: 350px" class="col-sm-8 select-table  table-striped">
        <table id="bootstrap-table" data-mobile-responsive="true"></table>
    </div>
    <div id="div2" style="height: 350px" class="col-sm-8 select-table  table-striped">
        <table id="bootstrap-table2" data-mobile-responsive="true"></table>
    </div>
</div>
<div th:include="include :: footer"></div>
<script th:inline="javascript">
    var prefix = ctx + "mydo/mydojob";
    var phaseDatas = [[${@dict.getType('execution_phase')}]];


    layui.use('laydate', function () {
        var laydates = layui.laydate;
        laydates.render({
            elem: '#startTime'
            , type: 'datetime',
            /* ,range: '到' */
            format: 'yyyy-MM-dd HH:mm:ss'
        })
    });

    layui.use('laydate', function () {
        var laydates = layui.laydate;
        laydates.render({
            elem: '#finishTime'
            , type: 'datetime',
            /* ,range: '到' */
            format: 'yyyy-MM-dd HH:mm:ss'
        })
    });


    $(document).ready(function () {
        $.post("/bas/inoroutType/list",{inOrOutTypeId:1},function(data){


            $("#inOrOut").append("<option value=''>全部</option>");
            // alert(data.rows[0].inOrOut);
            for(var i=0;i<data.total;i++){
                $("#inOrOut").append("<option value="+data.rows[i].inOrOut+">"+data.rows[i].inOrOutTypeName+"</option>");
            }
        });
        $.table.search();
    });


//子表
    var options2 = {
    	url:"",
        updateUrl: ctx + "mydo/stockindetail/edit/{id}",
        search: false,
        showRefresh: true,
        showColumns: true,
        minimumCountColumns: 2,
        clickToSelect: true,//是否启用点击选中行
        // height: $("#div2").height() / 1,
        sortName: "assignNum",
        sortOrder: "desc",
        modalName: "入库单据子表",
        method: 'post',
        striped: true, //是否显示行间隔色
        pagination: true,//显示分页
        sidePagination: "client",
        pageNumber: 1,
        pageSize: 15,
        pageList: [10, 25],
        singleSelect: true,
        uniqueId : 'jobDetailId',
        columns:
            [{
                checkbox: true,
            },
                {
                    field: 'jobDetailId',
                    title: '子作业号'
                },
                {
                    field: 'jobId',
                    title: '作业号',
                    sortable: true
                },
                {
                    field: 'lotNo',
                    title: '批号',
                    visible: true
                },

                // {
                //     field: 'productGuid',
                //     title: '物资guid',
                //     visible: false
                // },
                {
                    field: 'productId',
                    title: '物品编号',
                    align: 'center'

                },
                {
                    field: 'productName',
                    title: '物品名称',
                    align: 'center'

                },
                {
                    field: 'productDetailId',
                    title: '子物品编号',
                    align: 'center'

                },
                {
                    field: 'barcodeDetail',
                    title: '子件编码',
                    align: 'center'

                },
                {
                    field: 'inQuantity',
                    title: '数量',
                    sortable: true
                },
                {
                    field: 'inOrOutId',
                    title: '入库单号',
                    visible: true

                },
                {
                    title: '操作',
                    align: 'center',
                    formatter: function(value, row, index) {
                        var actions = [];
                        actions.push('<a class="btn btn-danger btn-xs " href="javascript:void(0)" onclick="removell(\'' + row.jobDetailId + '\')" ><i class="fa fa-edit"></i>删除</a> ');
                        return actions.join('');
                    }
                }]
    };
    $('#bootstrap-table2').bootstrapTable(options2);
    //主表
    var options = {
        url: prefix + "/list",
        detailView: false,//父子表
        height: $("#div1").height() / 1,
        search: true,
        showRefresh: true,
        showColumns: true,
        minimumCountColumns: 2,
        clickToSelect: true,//是否启用点击选中行
        createUrl: prefix + "/add",
        updateUrl: prefix + "/edit/{id}",
        removeUrl: prefix + "/remove",
        handFinishUrl: prefix + "/handFinish",
        handInvalidUrl: prefix + "/handInvalid",
        changeJobStatusUrl: prefix + "/changeJobStatus",
        changeJobpriorityUrl: prefix + "/changeJobpriority",
        sortName: "createTime",
        sortOrder: "desc",
        modalName: "入库作业信息",
        singleSelect: true,
        sureUrl: prefix + "/sure",
        auditUrl: prefix + "/audit",
        receiptSureUrl: prefix + "/receiptSure",
        receiptCancleUrl: prefix + "/receiptCancle",
        deleteAllUrl: prefix + "/deleteAll",
        columns: [{
            checkbox: true
        },
            {
                field: 'jobId',
                title: '作业号'
            },
            {
                field: 'status',
                title: '作业状态',
                formatter: function (value, row, index) {
                    if (value == 0) {
                        return "挂起(暂停)";
                    } else if (value == 1) {
                        return "未执行";
                    } else if (value == 2) {
                        return "待执行";
                    } else if (value == 3) {
                        return "正执行";
                    } else if (value == 4) {
                        return "已完成";
                    } else if (value == 5) {
                        return "已作废";
                    } else if (value == 6) {
                        return "需盘点";
                    } else if (value == 7) {
                        return "请求开始视频盘点";
                    } else if (value == 8) {
                        return "出库等待手持机确认";
                    }
                }
            },
            {
                field: 'taskNo',
                title: '任务号'
            },

            {
                field: 'trayCode',
                title: '托盘条码'
            },
            {
                field: 'roadwayId',
                title: '巷道'
            },
            {
                field: 'cargoSpaceId',
                title: '货位'
            },
            {
                field: 'workshopId',
                title: '层'
            },
            {
                field: 'priority',
                title: '优先级'
            },
            {
                field: 'executionPhase',
                title: '执行阶段',
                formatter: function(value, row, index) {
                    return $.table.selectDictLabel(phaseDatas, value);
                }
            },
            {
                field: 'inOrOut',
                title: '出入库类型',
                formatter: function (value, row, index) {
                    if (value == 1) {
                        return "物资入库";
                    } else if (value == 9) {
                        return "托盘入库";
                    } else if (value == 3) {
                        return "回流入库";
                    } else if (value == 4) {
                        return "盘点入库";
                    }

                }
            },
            {
                field: 'createTime',
                title: '建立时间'
            },
            {
                field: 'startTime',
                title: '开始时间'
            },
            {
                field: 'finishTime',
                title: '完成时间'
            },

            {
                field: 'jdbz',
                title: '阶段标志'
            },

            {
                field: 'entranceId',
                title: '入口'
            },
            ],
        //双击显示子表
        onClickRow: function (t, e) {
                options2.url = ctx + "mydo/jobdetail/list?jobId=" + t.jobId;
                $('#bootstrap-table2').bootstrapTable("refresh", options2)
            }
    };
    $.table.init(options);
    // $('#bootstrap-table').bootstrapTable(options)

    function handFinish() {
        table.set();
        var rows = $.common.isEmpty(table.options.uniqueId) ? $.table.selectFirstColumns() : $.table.selectColumns(table.options.uniqueId);
        if (rows.length == 0) {
            $.modal.alertWarning("请至少选择一条记录！");
            return;
        }
        if (rows.length > 1) {
            $.modal.alertWarning("只允许选择一条记录！");
            return;
        }
        $.modal.confirm("确认要手动完成选中的" + rows.length + "条作业吗?", function () {
            var url = table.options.handFinishUrl;
            var data = {"ids": rows.join()};
            $.operate.submit(url, "post", "json", data);
        });
    }

    function updateDetail(id) {
        table.set();
        var url = ctx + "mydo/jobdetail/edit{id}".replace("{id}", id);
        $.modal.open("修改单据明细", url);
    }

    function handInvalid() {

        table.set();
        var rows = $.common.isEmpty(table.options.uniqueId) ? $.table.selectFirstColumns() : $.table.selectColumns(table.options.uniqueId);
        if (rows.length == 0) {
            $.modal.alertWarning("请至少选择一条记录！");
            return;
        }
        if (rows.length > 1) {
            $.modal.alertWarning("只允许选择一条记录！");
            return;
        }
        $.modal.confirm("确认要手动作废选中的" + rows.length + "条作业吗?", function () {
            var url = table.options.handInvalidUrl;
            var data = {"ids": rows.join()};
            $.operate.submit(url, "post", "json", data);
        });
    }

    function changeJobStatus() {
        table.set();
        var rows = $.common.isEmpty(table.options.uniqueId) ? $.table.selectFirstColumns() : $.table.selectColumns(table.options.uniqueId);
        if (rows.length == 0) {
            $.modal.alertWarning("请至少选择一条记录！");
            return;
        }
        if (rows.length > 1) {
            $.modal.alertWarning("只允许选择一条记录！");
            return;
        }
        $.modal.confirm("确认要更改选中的" + rows.length + "条作业状态吗?", function () {
            var url = table.options.changeJobStatusUrl;
            var data = {"ids": rows.join()};
            $.operate.submit(url, "post", "json", data);
        });
    }
    function changeJobpriority(a) {
        table.set();
        var rows = $.common.isEmpty(table.options.uniqueId) ? $.table.selectFirstColumns() : $.table.selectColumns(table.options.uniqueId);
        if (rows.length == 0) {
            $.modal.alertWarning("请至少选择一条记录！");
            return;
        }
        // if (rows.length > 1) {
        //     $.modal.alertWarning("只允许选择一条记录！");
        //     return;
        // }
        $.modal.confirm("确认要更改选中的" + rows.length + "条作业优先级吗?", function () {
            var url = table.options.changeJobpriorityUrl;
            var data = {"ids": rows.join(),"pro": a};
            $.operate.submit(url, "post", "json", data);
        });
    }


    function removell(jobDetailId) {
        if (jobDetailId == null){
            $.modal.alertWarning("请至少选择一条记录！");
            return;
        }
        $.modal.confirm("确认要手动删除作业id为" + jobDetailId + "的子作业吗?", function () {
            var url = "/mydo/jobdetail/removel";
            var data = {"ids": jobDetailId};
            $.operate.submit(url, "post", "json", data);

        });
        var rows = $.common.isEmpty(table.options.uniqueId) ? $.table.selectFirstColumns() : $.table.selectColumns(table.options.uniqueId);
        options2.url = ctx + "mydo/jobdetail/list?jobId=" +rows.jobId;
        $('#bootstrap-table2').bootstrapTable("refresh", options2)
    }

</script>
</body>
</html>